package cc.sheji.controller;

import cc.sheji.Service.ShareLogService;
import cc.sheji.domain.JsonResult;
import cc.sheji.domain.PersonAuthQueryCriteria;
import cc.sheji.domain.ShareLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RestController

@RequestMapping(value = "/api/v1/shareLog")
public class ShareLogController {


    @Autowired
    ShareLogService shareLogService;

    @RequestMapping("/{id}")
    public JsonResult get(@PathVariable("id") Long id) throws Exception {
        return JsonResult.Success(shareLogService.get(id));
    }

    @PostMapping()
    public JsonResult create(@RequestBody @Validated ShareLog entity) {
        entity.setId(null);
        return JsonResult.Success(shareLogService.create(entity));
    }

    @PutMapping("/{id}")
    public JsonResult update(@PathVariable(name = "id") Long id,  @RequestBody ShareLog entity) {
        entity.setId(id);
        return JsonResult.Success(shareLogService.update(entity));
    }

    @GetMapping()
    public JsonResult get(PersonAuthQueryCriteria criteria , Pageable pageable) throws InterruptedException {
        return JsonResult.Success(shareLogService.list(criteria,pageable));
    }

}
